

var path = require('path')
var routerApi = require('../../utils/routeString.js')(__filename, __dirname);
var utils = require('../../utils/index.js')
var validate = utils.validate;
var SqlHelper = utils.SqlHelper;
var jwt = require('../../utils/jwt.js')
var dateHelper = require('../../utils/date.js')


var getuserdata = async function (req, res) {
    var body = req.body || req.query;

    if (!body.token) {
        return res.send({ code: 0, msg: '无效请求, token error' });
    }

    // 授权确认
    var tokenData = await jwt.decode(body.token);
    if (!tokenData || !tokenData.userid) {
        return res.send({ code: 0, msg: '服务器忙...1002' });
    }

    var sqlHelper = new SqlHelper('scatls_zpgame_180121');
    var userdata = await sqlHelper.asyncSelect({ openid: tokenData.userid });

    return res.send({ code: 1, userdata: userdata[0] });
}

var analysisFn = function (req, res, next) {
    var body = req.body || req.query;

    var cmd = body.cmd;

    // 命令解析
    if (!cmd) {
        return res.send({ code: 0, msg: '无效请求, cmd参数出错' });
    }

    switch (cmd) {
        case 'liuyan':  // 留言
            liuyan({ req: req, res: res }, cj)
            break;
        case 'dianzan':
            dianzan(req, res);  // 点赞
            break;
        case 'list':
            getList(req, res);  // 显示留言列表
            break;
        default:
            return res.send({ code: 0, msg: '无效请求, cmd参数出错' });
    }
}

server.post({ path: routerApi, name: routerApi }, analysisFn)